//
//  RWIconButton.m
//  04-ipadQQ
//
//  Created by 紫荆秋雪 on 16/4/7.
//  Copyright © 2016年 紫荆秋雪. All rights reserved.
//

#import "RWIconButton.h"

@implementation RWIconButton

- (instancetype)initWithFrame:(CGRect)frame{

    self = [super initWithFrame:frame];
    if ( self ) {
        
        //1 设置头像
        [self setImage:[UIImage imageNamed:@"lufy"] forState:UIControlStateNormal];
        
        //2 设置名称
        [self setTitle:@"RWIpad" forState:UIControlStateNormal];
        
        //3 设置文字颜色
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        
        //4 设置文字对齐方式
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        
        //5 设置图片显示模式
        self.contentMode = UIViewContentModeCenter;
    }
    return self;
}

- (void)layoutSubviews{

    [super layoutSubviews];
    
    //判断屏幕旋转
    if (Lanscape) {
        
        //设置图片frame
        self.imageView.x = 0;
        self.imageView.y = 0;
        self.imageView.width = self.width;
        self.imageView.height = self.width;
        
        self.imageView.layer.cornerRadius = 10;
        
        //设置label
        self.titleLabel.x = 0;
        self.titleLabel.y = self.imageView.height + 10;
        self.titleLabel.width = self.width;
        self.titleLabel.height = 50;
    }else {
    
        //设置图片frame
        self.imageView.x = 0;
        self.imageView.y = 0;
        self.imageView.width = self.width;
        self.imageView.height = self.width;
        
        //设置label
        self.titleLabel.hidden = YES;
        
    }
}

@end
